package com.ac.util;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import com.ac.model.AuthApi;
import com.ac.model.AuthMenu;
import com.ac.model.AuthUser;

import lombok.AllArgsConstructor;

@Component
@AllArgsConstructor
public class RootPath {

	static RootPath manger;

	final MongoTemplate mongo;

	@PostConstruct
	public void init() {
		manger = this;
	}

	/**
	 * 将所有tree结构的表进行更新
	 */
	public static void start() {
		// api表
		List<AuthApi> findAll = manger.mongo.findAll(AuthApi.class);
		for (AuthApi authApi : findAll) {
			TreeUtil.setRootPath(authApi, AuthApi.class, true);
		}
		// menu表
		List<AuthMenu> findAll1 = manger.mongo.findAll(AuthMenu.class);
		for (AuthMenu authApi : findAll1) {
			TreeUtil.setRootPath(authApi, AuthMenu.class, true);
		}
		// user表
		List<AuthUser> findAll2 = manger.mongo.findAll(AuthUser.class);
		for (AuthUser authApi : findAll2) {
			TreeUtil.setRootPath(authApi, AuthUser.class, true);
		}
	}

}
